home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / u_man / cat3 / Tcl / format.z / format
Encoding:
Text File  |  1998-10-30  |  11.3 KB  |  265 lines

  1.  
  2.  
  3.  
  4. ffffoooorrrrmmmmaaaatttt((((3333TTTTccccllll))))                                                      ffffoooorrrrmmmmaaaatttt((((3333TTTTccccllll))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      format - Format a string in the style of sprintf
  10.  
  11. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.      ffffoooorrrrmmmmaaaatttt _f_o_r_m_a_t_S_t_r_i_n_g ?_a_r_g _a_r_g ...?
  13.  
  14.  
  15. IIIINNNNTTTTRRRROOOODDDDUUUUCCCCTTTTIIIIOOOONNNN
  16.      This command generates a formatted string in the same way as the ANSI C
  17.      sssspppprrrriiiinnnnttttffff procedure (it uses sssspppprrrriiiinnnnttttffff in its implementation).  _F_o_r_m_a_t_S_t_r_i_n_g
  18.      indicates how to format the result, using %%%% conversion specifiers as in
  19.      sssspppprrrriiiinnnnttttffff, and the additional arguments, if any, provide values to be
  20.      substituted into the result.  The return value from ffffoooorrrrmmmmaaaatttt is the
  21.      formatted string.
  22.  
  23.  
  24. DDDDEEEETTTTAAAAIIIILLLLSSSS OOOONNNN FFFFOOOORRRRMMMMAAAATTTTTTTTIIIINNNNGGGG
  25.      The command operates by scanning _f_o_r_m_a_t_S_t_r_i_n_g from left to right. Each
  26.      character from the format string is appended to the result string unless
  27.      it is a percent sign.  If the character is a %%%% then it is not copied to
  28.      the result string.  Instead, the characters following the %%%% character are
  29.      treated as a conversion specifier.  The conversion specifier controls the
  30.      conversion of the next successive _a_r_g to a particular format and the
  31.      result is appended to the result string in place of the conversion
  32.      specifier.  If there are multiple conversion specifiers in the format
  33.      string, then each one controls the conversion of one additional _a_r_g.  The
  34.      ffffoooorrrrmmmmaaaatttt command must be given enough _a_r_gs to meet the needs of all of the
  35.      conversion specifiers in _f_o_r_m_a_t_S_t_r_i_n_g.
  36.  
  37.      Each conversion specifier may contain up to six different parts:  an XPG3|
  38.      position specifier, a set of flags, a minimum field width, a precision, a
  39.      length modifier, and a conversion character.  Any of these fields may be
  40.      omitted except for the conversion character.  The fields that are present
  41.      must appear in the order given above.  The paragraphs below discuss each
  42.      of these fields in turn.
  43.  
  44.      If the %%%% is followed by a decimal number and a $$$$, as in ``%%%%2222$$$$dddd'', then   |
  45.      the value to convert is not taken from the next sequential argument.     |
  46.      Instead, it is taken from the argument indicated by the number, where 1  |
  47.      corresponds to the first _a_r_g.  If the conversion specifier requires      |
  48.      multiple arguments because of **** characters in the specifier then         |
  49.      successive arguments are used, starting with the argument given by the   |
  50.      number.  This follows the XPG3 conventions for positional specifiers.  If|
  51.      there are any positional specifiers in _f_o_r_m_a_t_S_t_r_i_n_g then all of the      |
  52.      specifiers must be positional.
  53.  
  54.      The second portion of a conversion specifier may contain any of the
  55.      following flag characters, in any order:
  56.  
  57.      ----         Specifies that the converted argument should be left-justified
  58.                in its field (numbers are normally right-justified with leading
  59.                spaces if needed).
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. ffffoooorrrrmmmmaaaatttt((((3333TTTTccccllll))))                                                      ffffoooorrrrmmmmaaaatttt((((3333TTTTccccllll))))
  71.  
  72.  
  73.  
  74.      ++++         Specifies that a number should always be printed with a sign,
  75.                even if positive.
  76.  
  77.      _s_p_a_c_e     Specifies that a space should be added to the beginning of the
  78.                number if the first character isn't a sign.
  79.  
  80.      0000         Specifies that the number should be padded on the left with
  81.                zeroes instead of spaces.
  82.  
  83.      ####         Requests an alternate output form. For oooo and OOOO conversions it
  84.                guarantees that the first digit is always 0000.  For xxxx or XXXX
  85.                conversions, 0000xxxx or 0000XXXX (respectively) will be added to the
  86.                beginning of the result unless it is zero.  For all floating-
  87.                point conversions (eeee, EEEE, ffff, gggg, and GGGG) it guarantees that the
  88.                result always has a decimal point.  For gggg and GGGG conversions it
  89.                specifies that trailing zeroes should not be removed.
  90.  
  91.      The third portion of a conversion specifier is a number giving a minimum
  92.      field width for this conversion.  It is typically used to make columns
  93.      line up in tabular printouts.  If the converted argument contains fewer
  94.      characters than the minimum field width then it will be padded so that it
  95.      is as wide as the minimum field width.  Padding normally occurs by adding
  96.      extra spaces on the left of the converted argument, but the 0000 and ---- flags
  97.      may be used to specify padding with zeroes on the left or with spaces on
  98.      the right, respectively.  If the minimum field width is specified as ****
  99.      rather than a number, then the next argument to the ffffoooorrrrmmmmaaaatttt command
  100.      determines the minimum field width; it must be a numeric string.
  101.  
  102.      The fourth portion of a conversion specifier is a precision, which
  103.      consists of a period followed by a number.  The number is used in
  104.      different ways for different conversions.  For eeee, EEEE, and ffff conversions it
  105.      specifies the number of digits to appear to the right of the decimal
  106.      point.  For gggg and GGGG conversions it specifies the total number of digits
  107.      to appear, including those on both sides of the decimal point (however,
  108.      trailing zeroes after the decimal point will still be omitted unless the
  109.      #### flag has been specified).  For integer conversions, it specifies a
  110.      minimum number of digits to print (leading zeroes will be added if
  111.      necessary).  For ssss conversions it specifies the maximum number of
  112.      characters to be printed; if the string is longer than this then the
  113.      trailing characters will be dropped.  If the precision is specified with
  114.      **** rather than a number then the next argument to the ffffoooorrrrmmmmaaaatttt command
  115.      determines the precision; it must be a numeric string.
  116.  
  117.      The fifth part of a conversion specifier is a length modifier, which must
  118.      be hhhh or llll.  If it is hhhh it specifies that the numeric value should be
  119.      truncated to a 16-bit value before converting.  This option is rarely
  120.      useful.  The llll modifier is ignored.
  121.  
  122.      The last thing in a conversion specifier is an alphabetic character that
  123.      determines what kind of conversion to perform.  The following conversion
  124.      characters are currently supported:
  125.  
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. ffffoooorrrrmmmmaaaatttt((((3333TTTTccccllll))))                                                      ffffoooorrrrmmmmaaaatttt((((3333TTTTccccllll))))
  137.  
  138.  
  139.  
  140.      dddd         Convert integer to signed decimal string.
  141.  
  142.      uuuu         Convert integer to unsigned decimal string.
  143.  
  144.      iiii         Convert integer to signed decimal string;  the integer may
  145.                either be in decimal, in octal (with a leading 0000) or in
  146.                hexadecimal (with a leading 0000xxxx).
  147.  
  148.      oooo         Convert integer to unsigned octal string.
  149.  
  150.      xxxx or XXXX    Convert integer to unsigned hexadecimal string, using digits
  151.                ``0123456789abcdef'' for xxxx and ``0123456789ABCDEF'' for XXXX).
  152.  
  153.      cccc         Convert integer to the 8-bit character it represents.
  154.  
  155.      ssss         No conversion; just insert string.
  156.  
  157.      ffff         Convert floating-point number to signed decimal string of the
  158.                form _x_x._y_y_y, where the number of _y's is determined by the
  159.                precision (default: 6).  If the precision is 0 then no decimal
  160.                point is output.
  161.  
  162.      eeee or eeee    Convert floating-point number to scientific notation in the
  163.                form _x._y_y_yeeee++++_____z_z, where the number of _y's is determined by the
  164.                precision (default: 6).  If the precision is 0 then no decimal
  165.                point is output.  If the EEEE form is used then EEEE is printed
  166.                instead of eeee.
  167.  
  168.      gggg or GGGG    If the exponent is less than -4 or greater than or equal to the
  169.                precision, then convert floating-point number as for %%%%eeee or %%%%EEEE.
  170.                Otherwise convert as for %%%%ffff.  Trailing zeroes and a trailing
  171.                decimal point are omitted.
  172.  
  173.      %%%%         No conversion: just insert %%%%.
  174.  
  175.      For the numerical conversions the argument being converted must be an
  176.      integer or floating-point string; format converts the argument to binary
  177.      and then converts it back to a string according to the conversion
  178.      specifier.
  179.  
  180.  
  181. DDDDIIIIFFFFFFFFEEEERRRREEEENNNNCCCCEEEESSSS FFFFRRRROOOOMMMM AAAANNNNSSSSIIII SSSSPPPPRRRRIIIINNNNTTTTFFFF
  182.      The behavior of the format command is the same as the ANSI C sssspppprrrriiiinnnnttttffff     |
  183.      procedure except for the following differences:
  184.  
  185.      [1]  %%%%pppp and %%%%nnnn specifiers are not currently supported.                   |
  186.  
  187.      [2]  For %%%%cccc conversions the argument must be a decimal string, which will
  188.           then be converted to the corresponding character value.
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. ffffoooorrrrmmmmaaaatttt((((3333TTTTccccllll))))                                                      ffffoooorrrrmmmmaaaatttt((((3333TTTTccccllll))))
  203.  
  204.  
  205.  
  206.      [3]  The llll modifier is ignored;  integer values are always converted as  |
  207.           if there were no modifier present and real values are always        |
  208.           converted as if the llll modifier were present (i.e. type ddddoooouuuubbbblllleeee is    |
  209.           used for the internal representation).  If the hhhh modifier is        |
  210.           specified then integer values are truncated to sssshhhhoooorrrrtttt before         |
  211.           conversion.
  212.  
  213.  
  214. KKKKEEEEYYYYWWWWOOOORRRRDDDDSSSS
  215.      conversion specifier, format, sprintf, string, substitution
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.